#include QMK_KEYBOARD_H

const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
     [0] = LAYOUT(KC_TAB, MT(2), KC_CALCULATOR, KC_BSPACE, KC_7, KC_8, KC_9, KC_LGUI, KC_4, KC_5, KC_6, KC_PGDN, KC_1, KC_2, KC_3, LT(1,KC_ENTER)),
     [1] = LAYOUT(RGB_M_SW, RGB_M_SN, RGB_M_K, RGB_M_X, RGB_MOD, RGB_RMOD, RGB_HUI, RGB_HUD, RGB_SAI, RGB_SAD, RGB_VAI, RGB_VAD, RGB_SPI, RGB_SPD, RGB_TOG, KC_TRNS),
     [2] = LAYOUT(KC_TAB, MT(0), KC_HOME, KC_INSERT, KC_TRNS, KC_UP, KC_TRNS, AU_ON, KC_LEFT, KC_DOWN, KC_RIGHT, KC_N, PRINT_ON, PRINT_OFF, KC_SPACE, KC_SPACE),
};
const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt) {


	switch (id) {
		case 0:
			if (record->event.pressed) {
				return MACRO( T(1), T(2), T(3), T(4), T(1), T(2), T(3), T(4), END );
			}
			break;
		case 1:
			if (record->event.pressed) {
				return MACRO( D(A), D(O), D(E), U(A), U(O), D(U), U(E), D(A), U(U), D(O), D(E), U(A), U(O), D(U), U(E), D(A), U(U), D(O), D(E), U(A), D(U), U(O), U(E), U(U), END );
			}
			break;
		case 2:
			if (record->event.pressed) {
				return MACRO( D(A), D(A), D(A), D(A), D(A), D(A), D(A), D(A), D(A), D(A), D(A), D(A), D(A), T(A), END );
			}
			break;
		case 3:
			if (record->event.pressed) {
				return MACRO( D(LSFT), T(A), U(LSFT), T(O), D(LSFT), T(U), U(LSFT), D(LSFT), D(E), D(U), U(LSFT), U(E), U(U), T(LSFT), END );
			}
			break;
	}
	return MACRO_NONE;
}

static void render_logo(void) {
    static const char PROGMEM qmk_logo[] = {0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f, 0x90, 0x91, 0x92, 0x93, 0x94, 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf, 0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf, 0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0};
    oled_write_P(qmk_logo, true);
}

#ifdef OLED_DRIVER_ENABLE
void oled_task_user(void) { render_logo(); }
#endif

void encoder_update_user(uint8_t index, bool clockwise) {
  if (index == 0) {
    if (clockwise) {
      tap_code(KC_AUDIO_VOL_UP);
    } else {
      tap_code(KC_AUDIO_VOL_DOWN);
    }
  } else if (index == 1) {
    if (clockwise) {
      tap_code(KC_BRIGHTNESS_UP);
    } else {
      tap_code(KC_BRIGHTNESS_DOWN);
		}
    }
  }
}


bool process_record_user(uint16_t keycode, keyrecord_t *record) {

  return true;
}

void matrix_init_user(void) { render_logo(); }

void matrix_scan_user(void) {}

void led_set_user(uint8_t usb_led) {}
